const { getTenants, getAuditTenants, updateAuditTenants, searchTenants, getTenantsById,
    changeTenantsById } = require('../dao/tenantsDao');
//获取所有已审核租客
module.exports.getTenants = async ({ searchType, searchValue, pageSize, currentPage }) => {
    if (searchValue) {
        const data = await searchTenants({ searchType, searchValue, pageSize, currentPage });
        return {
            message: '租客数据查询成功',
            status: 1,
            data: data
        }
    } else {
        try {
            const data = await getTenants({ pageSize, currentPage });
            return {
                message: '租客数据获取成功',
                status: 1,
                data: data
            }
        } catch (error) {
            console.log('error', error);
            return {
                message: '租客数据获取失败',
                status: 0
            }
        }
    }
}
//获取所有未审核租客
module.exports.getAuditTenants = async ({ pageSize, currentPage }) => {
    const data = await getAuditTenants({ pageSize, currentPage });
    return {
        message: '租客数据获取成功',
        status: 1,
        data: data
    }
},
    //获取要修改的未审核租客
    module.exports.updateAuditTenants = async ({ _id }) => {
        const data = await updateAuditTenants({ _id });
        if (data.nModified === 1) {
            return {
                message: '租客数据修改成功',
                status: 1
            }
        } else {
            return {
                message: '租客数据修改失败',
                status: 0
            }
        }
    }


//通过id获取租客信息
module.exports.getTenantsById = async (id) => {
    const data = await getTenantsById(id);
    if (data.length) {
        return {
            message: '获取成功',
            data,
            status: 1
        }
    } else {
        return {
            message: '没有该数据',
            data,
            status: 0
        }
    }
}



//通过id修改租客的信息
module.exports.changeTenantsById = async (code) => {
    const data = await changeTenantsById(code);
    return data
}